import React, { useContext,useState } from 'react';
import {Context}from '../../provider'
const Index = () => {
    const [state,dispatch] = useContext(Context)
    const [cities] = useState(['上海','杭州','深圳','西安'])
    return (
        <div>
            <p>{state.city}</p>
            {cities.map(item=>{
                return (
                    <div key={item}>
                        <button onClick={()=>{
                            dispatch({
                                type:"changeCity",
                                val:item
                            })
                        }}>{item}</button>
                    </div>
                )
            })}
            
        </div>
    );
}

export default Index;
